﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DevExpress.Web.ASPxEditors;

using Entities;
using BLL;

namespace Stationery.UC
{
    public partial class UC_NewsHot : System.Web.UI.UserControl
    {
        //protected System.Web.UI.HtmlControls.HtmlGenericControl marquee;
        protected System.Web.UI.WebControls.DataList DataList;
        BLL_News bll_News = new BLL_News();

        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = bll_News.Get_HotNews();
            if (dt == null)
                return;
            if (dt.Rows.Count <= 0)
            {                
                return;
            }
            
            DataList.DataSource = dt; 
            DataList.DataBind();               
        }        

        protected void DataList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item != null)
            {
                DataRowView dtrv = (DataRowView)e.Item.DataItem;

                HyperLink hltitle = (HyperLink)e.Item.FindControl("HyperLinkTitle1");
                hltitle.Text = dtrv["Title"].ToString();
                hltitle.NavigateUrl = "~/News.aspx?viewtype=detail&gid=" + dtrv["Group_id"].ToString() + "&newsid=" + dtrv["News_id"].ToString();
                ASPxBinaryImage binaryImage = (ASPxBinaryImage)e.Item.FindControl("ASPxBinaryImageData");
                if (dtrv["Image_data"] != DBNull.Value)
                {
                    binaryImage.ContentBytes = (byte[])dtrv["Image_data"];
                }
                else
                {
                    binaryImage.ContentBytes = null;
                    binaryImage.Visible = false;
                }                
            }
        }

        protected string GetLinkDetail(string group_id, string news_id)
        {
            string strURL = "";
            if (group_id == "")
                return strURL;
            if (news_id == "")
                return strURL;

            strURL = String.Format("News.aspx?viewtype=detail&gid={0}&newsid={1}", group_id, news_id);
            return strURL;
        }
    }
}